<?php
require_once("admin-header.php");
include_once("../fckeditor/fckeditor.php") ;
if (isset($_POST['syear']))
{
	require_once("../include/db_info.inc.php");
	require_once("../include/check_post_key.php");
	$starttime=intval($_POST['syear'])."-".intval($_POST['smonth'])."-".intval($_POST['sday'])." ".intval($_POST['shour']).":".intval($_POST['sminute']).":00";
	$endtime=intval($_POST['eyear'])."-".intval($_POST['emonth'])."-".intval($_POST['eday'])." ".intval($_POST['ehour']).":".intval($_POST['eminute']).":00";
	$SRtime=intval($_POST['SRyear'])."-".intval($_POST['SRmonth'])."-".intval($_POST['SRday'])." ".intval($_POST['SRhour']).":".intval($_POST['SRminute']).":00";
	$ERtime=intval($_POST['ERyear'])."-".intval($_POST['ERmonth'])."-".intval($_POST['ERday'])." ".intval($_POST['ERhour']).":".intval($_POST['ERminute']).":00";
//	echo $starttime;
//	echo $endtime;
	$title=mysql_real_escape_string($_POST['title']);
	$description=mysql_real_escape_string($_POST['description']);
	$Ckind=$_POST['ckind'];
/*	if (get_magic_quotes_gpc ())
	{
		$title = stripslashes ( $title);
		$description = stripslashes ( $description);
	}*/
	$cid=intval($_POST['cid']);
	if(!isset($_SESSION['administrator']) && !isset($_SESSION[$BM_ADMIN])) exit();
	$sql="UPDATE `bm_contest` set `bm_c_title`='$title',bm_c_description='$description',`bm_c_start`='$starttime',`bm_c_end`='$endtime',`bm_c_startreg`='$SRtime',`bm_c_endreg`='$ERtime',`bm_c_kind`='$Ckind' WHERE `bm_c_id`=$cid";
	//echo $sql;
	mysql_query($sql) or die(mysql_error());
	echo "<script>window.location.href=\"contest_list.php\";</script>";
	exit();
}
else
{
	$cid=intval($_GET['cid']);
	$sql="SELECT * FROM `bm_contest` WHERE `bm_c_id`=$cid";
	$result=mysql_query($sql);
	if (mysql_num_rows($result)!=1)
	{
		mysql_free_result($result);
		echo "No such Contest!";
		exit(0);
	}
	$row=mysql_fetch_assoc($result);
	$starttime=$row['bm_c_start'];
	$endtime=$row['bm_c_end'];
	$SRtime=$row['bm_c_startreg'];
	$ERtime=$row['bm_c_endreg'];
	$Ckind=$row['bm_c_kind'];
	$description=$row['bm_c_description'];
	$title=htmlspecialchars($row['bm_c_title']);
	mysql_free_result($result);
}
?>
    <form method=POST >
    <?php require_once("../include/set_post_key.php");?>
    <p align=center><font size=4 color=#333399>Edit a Contest</font></p>
    <input type=hidden name='cid' value=<?php echo $cid?>>
    <p align=left>Title:<input type=text name=title size=71 value='<?php echo $title?>'></p>
    
	<p align=left>Start Time:<br>&nbsp;&nbsp;&nbsp;
	Year:<input type=text name=syear value=<?php echo substr($starttime,0,4)?> size=4 >
    Month:<input type=text name=smonth value='<?php echo substr($starttime,5,2)?>' size=2 >
    Day:<input type=text name=sday size=2 value='<?php echo substr($starttime,8,2)?>'>
    Hour:<input type=text name=shour size=2 value='<?php echo substr($starttime,11,2)?>'>
    Minute:<input type=text name=sminute size=2 value=<?php echo substr($starttime,14,2)?>></p>
    
    <p align=left>End Time:<br>&nbsp;&nbsp;&nbsp;
    Year:<input type=text name=eyear value=<?php echo substr($endtime,0,4)?> size=4 >
    Month:<input type=text name=emonth value=<?php echo substr($endtime,5,2)?> size=2 >
    Day:<input type=text name=eday size=2 value=<?php echo substr($endtime,8,2)?>>
    Hour:<input type=text name=ehour size=2 value=<?php echo substr($endtime,11,2)?>> 
    Minute:<input type=text name=eminute size=2 value=<?php echo substr($endtime,14,2)?>></p>
    
	<p align=left>Start Register Time:<br>&nbsp;&nbsp;&nbsp;
    Year:<input type=text name=SRyear value=<?php echo substr($SRtime,0,4)?> size=4 >
    Month:<input type=text name=SRmonth value='<?php echo substr($SRtime,5,2)?>' size=2 >
    Day:<input type=text name=SRday size=2 value='<?php echo substr($SRtime,8,2)?>'>
    Hour:<input type=text name=SRhour size=2 value='<?php echo substr($SRtime,11,2)?>'>
    Minute:<input type=text name=SRminute size=2 value=<?php echo substr($SRtime,14,2)?>></p>
    
    <p align=left>End Register Time:<br>&nbsp;&nbsp;&nbsp;
    Year:<input type=text name=ERyear value=<?php echo substr($ERtime,0,4)?> size=4 >
    Month:<input type=text name=ERmonth value=<?php echo substr($ERtime,5,2)?> size=2 >
    Day:<input type=text name=ERday size=2 value=<?php echo substr($ERtime,8,2)?>>
    Hour:<input type=text name=ERhour size=2 value=<?php echo substr($ERtime,11,2)?>> 
    Minute:<input type=text name=ERminute size=2 value=<?php echo substr($ERtime,14,2)?>></p>
    <?php
    echo "Kind:<select name=ckind><option value=0 ".($Ckind == 0 ? "selected" : "").">组队赛</option><option value=1 ".($Ckind == 1 ? "selected" : "").">个人赛</option></select>"
		?>
    <br>
    <p align=left>Description:<br><!--<textarea rows=13 name=description cols=80></textarea>-->
<?php
$fck_description = new FCKeditor('description') ;
$fck_description->BasePath = '../fckeditor/' ;
$fck_description->Height = 300 ;
$fck_description->Width=600;
$fck_description->Value = $description ;
$fck_description->Create() ;

?>
<p><input type=submit value=Submit name=submit><input type=reset value=Reset name=reset></p>

</form>
<?php require_once("../bm-footer.php");?>

